package com.bupt.controller.common;

import com.bupt.annotation.AccessLimit;
import com.bupt.basic.DemandReportService;
import com.bupt.constants.ResponseResult;
import com.bupt.service.common.StrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@Api(tags = {"项目的规划"})
@RequestMapping("/api")
public class StrategyController {

    @Resource
    private StrategyService strategyService;

    @ApiOperation("开始规划")
    @AccessLimit(interfaceName = "开始规划")
    @PostMapping("/plan/projects/{projectId}")
    public Object plan(HttpServletRequest request,
                       @PathVariable("projectId")String projectId,
                       @RequestParam("strategy")String strategy,
                       @RequestParam(value = "layer",required = false)String layer,
                       @RequestParam(value = "resLimit",required = false)Integer resLimit,
                       @RequestParam(value = "hopLimit",required = false)Integer hopLimit,
                       @RequestParam(value = "selectedTraffic",required = false)String selectedTrafficStr){
        try{
           String[] selectedTraffic=new String[100];
           if(selectedTrafficStr!=null){
               selectedTraffic=selectedTrafficStr.split(",");
           }
            Object o = strategyService.plan(request, projectId, strategy, layer, resLimit, hopLimit, selectedTraffic);

           for(DemandReportService traffic : (List<DemandReportService>)strategyService.planRes(projectId)){
               System.out.println(traffic.getWorkRoute());
               System.out.println(traffic.getProtectRoute());

           }
           String message="规划成功数量:"+o;
           return ResponseResult.createOK(message);
        }catch (Exception e){
            return ResponseResult.createFail(e.getMessage());
        }
    }
}
